﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ROrganizer.Client;

namespace ROrganizer.UI.Models
{
    internal class Resolution : IComparable
    {
        public int? Width { get; set; }
        public int? Height { get; set; }

        public bool IsSpecified()
        {
            return this.Width != null && this.Height != null;
        }

        public static Resolution From(MetaEntry entry)
        {
            if (entry == null)
                return new Resolution { };

            return new Resolution
            { 
                Width = entry != null ? entry.Info.Width : default(int?), 
                Height = entry != null ? entry.Info.Height : default(int?) 
            };
        }

        int IComparable.CompareTo(object obj)
        {
            var second = obj as Resolution;

            if (second == null || second.Height == null || second.Width == null)
                return -1;

            if (this.Height == null || this.Width == null)
                return 1;

            if (this.Width == second.Width)
                return this.Height.Value.CompareTo(second.Height.Value);

            return this.Width.Value.CompareTo(second.Width.Value);
        }
    }
}
